package com.bykj.property.config.common.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yiming
 * @title: UserFilter
 * @projectName waste
 * @description: TODO
 * @date 2019/7/2822:54
 */
@Configuration
@Slf4j
public class UserFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;

        String path = request.getRequestURI().substring(request.getContextPath().length()).replaceAll("[/]+$", "");

        if(path.contains("/admin/")) {
            String type=(String)request.getSession().getAttribute("userType");
            if("0".equals(type)){
                return ;
            }
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
